<template>
  <page-header-wrapper :title="false">
    <a-card>
      <div class="table-page-search-wrapper">
        <a-form layout="inline">
          <a-row :gutter="48">
            <a-col :md="6" :sm="24">
              <a-form-item label="筛选">
                <a-input v-model="queryParam.keyword" placeholder="请输入商品串码后5位" />
              </a-form-item>
            </a-col>
            <a-col :md="(!advanced && 8) || 24" :sm="24">
              <span
                class="table-page-search-submitButtons"
                :style="(advanced && { float: 'right', overflow: 'hidden' }) || {}"
              >
                <a-button type="primary" :loading="loading" @click="handleSearch(queryParam)">查询</a-button>
                <a-button style="margin-left: 8px" @click="() => (queryParam = {})">重置</a-button>
              </span>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <a-table
        ref="table"
        size="default"
        :loading="loading"
        rowKey="key"
        :columns="columns"
        :data-source="loadData"
        :pagination="pagination"
        @change="handleTableChange"
      >
        <span slot="serial" slot-scope="text, record, index">
          {{ index + 1 }}
        </span>
        <span slot="action" slot-scope="text, record">
          <template>
            <a-tag color="#428bca" @click="handleGoodsDetail(record)">详情</a-tag>
          </template>
        </span>
      </a-table>
    </a-card>
  </page-header-wrapper>
</template>

<script>
export default {
  name: 'CashierMobileSearch',
  data() {
    return {
      mdl: null,
      priceMdl: null,
      visible: false,
      priceVisible: false,
      value: '',
      confirmLoading: false,
      priceLoading: false,
      // 高级搜索 展开/关闭
      advanced: false,
      // 查询参数
      queryParam: {
        pageNo: 1,
        pageSize: 10,
        queryCondition: '',
        status: '',
        types: '',
        brand: '',
      },
      pagination: {
        total: 0,
      },
      // 表头
      columns: [
        {
          title: '销售日期',
          dataIndex: 'inDate',
        },
        {
          title: '销售类型',
          dataIndex: 'goodsName',
        },
        {
          title: '业务分类',
          dataIndex: 'type',
        },
        {
          title: '业务名称',
          dataIndex: 'name',
        },
        {
          title: '业务号码',
          dataIndex: 'phone',
        },
        {
          title: '身份证',
          dataIndex: 'idCard',
        },
        {
          title: '销售员',
          dataIndex: 'xiaoshou',
        },
        {
          title: '销售门店',
          dataIndex: 'storeName',
        },
        {
          title: '操作',
          dataIndex: 'action',
          width: '150px',
          scopedSlots: { customRender: 'action' },
        },
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: [],
      loading: false,
      optionParam: {
        pageNo: 1,
        pageSize: 999,
        queryCondition: '',
        status: 1,
      },
      brandOption: [],
      classifyOption: [],
      optionAlertShow: false,
    }
  },
  // created() {
  //   this.handleSearch(this.queryParam)
  // },
  methods: {
    handleEdit () {
      this.confirmLoading = false
      this.visible = true
    },
    handleSearch(params) {
      this.loading = true
      setTimeout(() => {
        this.loadData = [
          {
            id: 1,
            inDate: '2023-09-15',
            goodsName: '销售',
            type: '销售',
            name: '家电',
            phone: '69217709863423',
            idCard: '69564321234543',
            xiaoshou: '测试',
            storeName: '达臻贸易王升',
          },
        ]
        this.loading = false
      }, 1000)
    },
    handleGoodsDetail(record) {
      this.$router.push({ path: `/goods/name/${record.id}` })
    },
    handleTableChange(pagination, filters, sorter) {
      const pager = { ...this.pagination }
      pager.current = pagination.current
 pager.pageSize = pagination.pageSize
      this.pagination = pager
      this.handleSearch({
        sortField: sorter.field,
        sortOrder: sorter.order,
        ...filters,
        pageNo: pagination.current,
        pageSize: pagination.pageSize,
        queryCondition: this.queryParam.queryCondition,
        status: this.queryParam.status,
        date: this.queryParam.date,
      })
    },
    handleCancel () {
      this.visible = false
      const form = this.$refs.createModal.form
      form.resetFields() // 清理表单数据（可不做）
    },
    handleOk () {
      this.visible = false
      this.confirmLoading = false
      const form = this.$refs.createModal.form
      this.$message.warn('开发中')
    },
  },
}
</script>
